<?php
class Object_Singleton {
	static $__instance__ = array();

	public function __construct($opt=array())
	{
		echo '__construct :' . __CLASS__ ."\n";
	}

	public function getInstance($name='__default__', $opt=array())
	{
		self::getInstanceAbstract($name, __CLASS__, $opt);
	}

	public function getInstanceAbstract($name='__default__', $class=null, $opt=array())
	{
		if(!array_key_exists($name , self::$__instance__) || !$__instance__[$name]) {
			if($class === null) {
				$class = __CLASS__;
			}
            self::$__instance__[$name] = new $class($opt);
		}
		return self::$__instance__[$name];
	}

} // end class


class test extends Object_Singleton {

	public function getInstance($name='__default__', $opt=array())
	{
		parent::getInstanceAbstract($name, __CLASS__);
	}
}
	$test = test::getInstance();
?>